package com.lt.contract.service.impl;


import com.lt.contract.bean.NM_CONTRACT_2019;
import com.lt.contract.bean.utils.ExcelColumn;
import com.lt.contract.bean.utils.ExcelImport;
import com.lt.contract.dao.NM_CONTRACT_2019Mapper;
import com.lt.contract.dao.NmMongoliaCircuitSharingDao;
import com.lt.contract.entity.InnovativeBusiness;
import com.lt.contract.entity.NmInternetOfThings;
import com.lt.contract.entity.NmMobileService;
import com.lt.contract.entity.NmMongoliaCircuitSharing;
import com.lt.contract.service.ImportServiceInterFace;
import com.lt.report.service.AsyncService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: yz
 * @Date:
 */
@Service
@Slf4j
public class ImportCServiceImpl implements ImportServiceInterFace {

    @Autowired
    NM_CONTRACT_2019Mapper nmContract2019Mapper;

    @Autowired
    NmMongoliaCircuitSharingDao nmMongoliaCircuitSharingDao;

    @Autowired
    AsyncService asyncService;

    @Override
    public String getBankListByExcel(InputStream in, String fileName) throws Exception {
        //选择文件中的列
        Integer[] arr = null;
        Integer[] arr2 = null;
        Integer[] arr3 = null;
        List<Integer[]> numList = new ArrayList<>();

        String tableName = "";
        if (fileName.contains("2019合同")) {
            arr = new Integer[]{2, 3, 4, 5, 6, 7, 19,36,37,38,39,40,41,42,43,44,45,46,47,48,49};
            arr2 = new Integer[]{2, 3, 4, 5, 6, 7, 24,25,38,39,40,41,42,43,44,45,46,47,48,49};
            arr3 = new Integer[]{2, 3, 4, 5, 6, 10, 29,34,38,39,40,41,42,43,44,45,46,47,48,49};
            numList.add(arr);
            numList.add(arr2);
            numList.add(arr3);
            tableName = "contract2019";
        }else if(fileName.contains("国内电路")){
            tableName ="nmMongoliaCircuitSharing";
        }else if(fileName.contains("创新业务")){
            tableName ="innovativeBusiness";
        }else if(fileName.contains("一站式")){
            tableName ="oneStopService";
        }else if(fileName.contains("移动业务")){
            tableName ="mobile";
        }else if(fileName.contains("物联网")){
            tableName ="InternetOfThings";
        }

        else {
            log.error("上传文件不符合规定");
            return "请上次相关文件";
        }
        //创建Excel工作薄
        Workbook work = this.getWorkbook(in, fileName);

        Sheet sheet = null;
        List<Sheet> sheets = new ArrayList<>();
        Row row = null;
        Cell cell = null;
//        for (int i = 0; i < work.getNumberOfSheets(); i++) {
//        for (int i = 0; i < 1; i++) {
        if (tableName.equals("contract2019")) {
            //项目合计
            sheets.add(work.getSheet("一站式业务2019.12"));
            sheets.add(work.getSheet("移动业务2019.12"));
            sheets.add(work.getSheet("创新业务2019.12"));
        } else {
            sheet = work.getSheetAt(0);//只取第一个Sheet
        }
        work = null;
        if (tableName.equals("contract2019")) {
            List<NM_CONTRACT_2019> list = listContract2019(sheets,numList);
            asyncService.executeContract2019(list);
//            nmContract2019Mapper.insertAll(list);
        } else if(tableName.equals("nmMongoliaCircuitSharing")) {
            List<List<NmMongoliaCircuitSharing>> lists =listNmMongoliaCircuitSharing(sheet);
           int size = lists.size();
            for (int i = 0; i <size ; i++) {
                List<NmMongoliaCircuitSharing> list = lists.get(i);
                asyncService.executeNmMSharing(list);
            }
        } else if(tableName.equals("innovativeBusiness")) {
            List<List<InnovativeBusiness>> lists =listInnovativeBusiness(sheet);
            int size = lists.size();
            for (int i = 0; i <size ; i++) {
                List<InnovativeBusiness> list = lists.get(i);
                asyncService.executeInnovative(list);
            }
        }else if(tableName.equals("mobile")) {
            List<List<NmMobileService>> lists =listNmMobile(sheet);
            int size = lists.size();
            for (int i = 0; i <size ; i++) {
                List<NmMobileService> list = lists.get(i);
                asyncService.executeMobile(list);
            }
        }else if(tableName.equals("InternetOfThings")) {
            List<List<NmInternetOfThings>> lists =listNmInternetOfThings(sheet);
            int size = lists.size();
            for (int i = 0; i <size ; i++) {
                List<NmInternetOfThings> list = lists.get(i);
                asyncService.executeInternetOfThings(list);
            }
        }
        else {
            return "请上次相关文件";
        }
        return "上传成功";
    }

    /**
     * 导入手工填写数据
     *
     * @param sheets 工在簿的多个sheet ,numList 选取工作簿的对应sheet 选取 的列号
     * @return
     */
    public List<NM_CONTRACT_2019> listContract2019(List<Sheet> sheets, List<Integer[]> numList) {
        List<NM_CONTRACT_2019> list = new ArrayList<>();
        Cell cell = null;
        for (int n = 0; n < sheets.size(); n++) {
            for (int j = sheets.get(n).getFirstRowNum() + 1; j <= sheets.get(n).getLastRowNum(); j++) {
                Row row = sheets.get(n).getRow(j);
                if (row == null || row.getFirstCellNum() == j || row.getCell(1) == null) {
                    continue;
                }
                NM_CONTRACT_2019 nm_contract_2019 = new NM_CONTRACT_2019();
                for (int y = row.getFirstCellNum(); y < row.getLastCellNum(); y++) {
                    cell = row.getCell(y);
                    if(cell==null || cell.toString().equals("")){
                        cell=row.createCell(y);
                    }
                    List<Integer> iList = Arrays.asList(numList.get(n));
                    if (iList.contains(y+1)) {//列从 索引 0 开始写入
                        if(n==0) {
                            switch (y+1) {
//                                arr = new Integer[]{2, 3, 4, 5, 6, 7, 19,36,37}; 38-49 1-12月收入
                                case 2:nm_contract_2019.setRepositoryNameVendor(cell.toString());break;
                                case 3: nm_contract_2019.setContractNoGlobal(cell.toString());System.out.println(nm_contract_2019.getContractNoGlobal()); break;
                                case 4: nm_contract_2019.setContractName(cell.toString()); break;
                                case 5: nm_contract_2019.setBusinessCoding(cell.toString()); break;
                                case 6:nm_contract_2019.setTrellisName(cell.toString()); break;
                                case 7:nm_contract_2019.setAccountManager(cell.toString()); break;
                                case 36:nm_contract_2019.setRemark1(cell.toString()); break;
                                case 37:String amount = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setProjectAmount(new BigDecimal(amount));
                                     break;
                                case 19:nm_contract_2019.setSignWay(cell.toString()); break;//签约方式
                                case 38:
                                    String amount1 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth1(new BigDecimal(amount1));
                                    break;
                                case 39:
                                    String amount2 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth2(new BigDecimal(amount2));
                                    break;
                                case 40:
                                    String amount3 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth3(new BigDecimal(amount3));
                                    break;
                                case 41:
                                    String amount4 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth4(new BigDecimal(amount4));
                                    break;
                                case 42:
                                    String amount5 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth5(new BigDecimal(amount5));
                                    break;
                                case 43:
                                    String amount6 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth6(new BigDecimal(amount6));
                                    break;
                                case 44:
                                    String amount7 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth7(new BigDecimal(amount7));
                                    break;
                                case 45:
                                    String amount8 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth8(new BigDecimal(amount8));
                                    break;
                                case 46:
                                    String amount9 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth9(new BigDecimal(amount9));
                                    break;
                                case 47:
                                    String amount10 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth10(new BigDecimal(amount10));
                                    break;
                                case 48:
                                    String amount11 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth11(new BigDecimal(amount11));
                                    break;
                                case 49:
                                    String amount12 = cell.toString().equals("") ? "0.0" : cell.toString();
                                    nm_contract_2019.setMonth12(new BigDecimal(amount12));
                                    break;


                            }
                        }else if(n==1){
                            //  arr2 = new Integer[]{2, 3, 4, 5, 6, 7, 24,25};

                            switch (y+1) {
                                case 2:nm_contract_2019.setRepositoryNameVendor(cell.toString());break;
                                case 3: nm_contract_2019.setContractNoGlobal(cell.toString()); break;
                                case 4: nm_contract_2019.setContractName(cell.toString()); break;
                                case 5: nm_contract_2019.setBusinessCoding(cell.toString()); break;
                                case 6:nm_contract_2019.setTrellisName(cell.toString()); break;
                                case 7:nm_contract_2019.setAccountManager(cell.toString()); break;
                                case 24:nm_contract_2019.setRemark1(cell.toString()); break;
                                case 25:String amount =cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setProjectAmount(new BigDecimal(amount)); break;
                                case 38		:String amount1		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth1	(new BigDecimal(amount1	));    break;
                                case 39		:String amount2		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth2	(new BigDecimal(amount2	));    break;
                                case 40		:String amount3		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth3	(new BigDecimal(amount3	));    break;
                                case 41		:String amount4		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth4	(new BigDecimal(amount4	));    break;
                                case 42		:String amount5		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth5	(new BigDecimal(amount5	));    break;
                                case 43		:String amount6		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth6	(new BigDecimal(amount6	));    break;
                                case 44		:String amount7		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth7	(new BigDecimal(amount7	));    break;
                                case 45		:String amount8		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth8	(new BigDecimal(amount8	));    break;
                                case 46		:String amount9		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth9	(new BigDecimal(amount9	));    break;
                                case 47		:String amount10		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth10	(new BigDecimal(amount10	));    break;
                                case 48		:String amount11		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth11	(new BigDecimal(amount11	));    break;
                                case 49		:String amount12		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth12	(new BigDecimal(amount12	));    break;

                            }
                        }else if(n==2){
                            //   arr3 = new Integer[]{2, 3, 4, 5, 6, 10, 29,34};
                            switch (y+1) {
                                case 2:nm_contract_2019.setTrellisName(cell.toString()); break;
                                case 3: nm_contract_2019.setAccountManager(cell.toString()); break;
                                case 4: nm_contract_2019.setContractNoGlobal(cell.toString()); break;
                                case 5: nm_contract_2019.setContractName(cell.toString()); break;
                                case 6:nm_contract_2019.setRepositoryNameVendor(cell.toString());break;
                                case 10:nm_contract_2019.setBusinessCoding(cell.toString());break;
                                case 29:nm_contract_2019.setRemark1(cell.toString());break;
                                case 34:String amount = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setProjectAmount(new BigDecimal(amount)); break;
                                case 38		:String amount1		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth1	(new BigDecimal(amount1	));    break;
                                case 39		:String amount2		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth2	(new BigDecimal(amount2	));    break;
                                case 40		:String amount3		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth3	(new BigDecimal(amount3	));    break;
                                case 41		:String amount4		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth4	(new BigDecimal(amount4	));    break;
                                case 42		:String amount5		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth5	(new BigDecimal(amount5	));    break;
                                case 43		:String amount6		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth6	(new BigDecimal(amount6	));    break;
                                case 44		:String amount7		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth7	(new BigDecimal(amount7	));    break;
                                case 45		:String amount8		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth8	(new BigDecimal(amount8	));    break;
                                case 46		:String amount9		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth9	(new BigDecimal(amount9	));    break;
                                case 47		:String amount10		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth10	(new BigDecimal(amount10	));    break;
                                case 48		:String amount11		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth11	(new BigDecimal(amount11	));    break;
                                case 49		:String amount12		 = cell.toString().equals("")? "0.0":cell.toString();nm_contract_2019.setMonth12	(new BigDecimal(amount12	));    break;

                            }
                        }
                    }
                }
                list.add(nm_contract_2019);
            }
        }
        return list;
    }

    /**
     * 导入国内分摊数据
     *
     * @param sheets 导入国内分摊数据
     * @return
     */
    public List<List<NmMongoliaCircuitSharing>> listNmMongoliaCircuitSharing(Sheet sheets) throws Exception {
        List<List<NmMongoliaCircuitSharing>> lists =new ArrayList<>();
        List<NmMongoliaCircuitSharing> list = new ArrayList<>();
        Cell cell = null;
            for (int j = sheets.getFirstRowNum() + 2; j <= sheets.getLastRowNum(); j++) {
                Row row = sheets.getRow(j);
                if (row == null || row.getFirstCellNum() == j || row.getCell(1) == null) {
                    continue;
                }
                NmMongoliaCircuitSharing nmMongoliaCircuitSharing = new NmMongoliaCircuitSharing();
                for (int y = row.getFirstCellNum(); y < 184; y++) {//表格有184列
                    cell = row.getCell(y);
                    if(cell==null || cell.toString().equals("")){
                        cell=row.createCell(y);
                    }
                    String methodName = ExcelColumn.excelColIndexToStrNew(y);
                    Class<?> c = Class.forName("com.lt.contract.entity.NmMongoliaCircuitSharing");
                    Object obj = nmMongoliaCircuitSharing;
                    Method method=c.getMethod(methodName, String.class);
                    method.invoke(obj, new Object[]{ExcelImport.getCellValue(cell)});
                }
                list.add(nmMongoliaCircuitSharing);
                int flag =200;
                if(j%flag==0||j == sheets.getLastRowNum()){
                    List<NmMongoliaCircuitSharing> copy = new ArrayList<>();
                    for (NmMongoliaCircuitSharing item: list ) {
                        copy.add(item);
                    }
                    lists.add(copy);
                    list.clear();
                }
            }
        return lists;
    }


    /**
     * 导入创新业务导入数据
     *
     * @param sheets 创新业务导入
     * @return
     */
    public List<List<InnovativeBusiness>> listInnovativeBusiness(Sheet sheets) throws Exception {
        List<List<InnovativeBusiness>> lists =new ArrayList<>();
        List<InnovativeBusiness> list = new ArrayList<>();
        Cell cell = null;
        for (int j = sheets.getFirstRowNum() + 1; j <= sheets.getLastRowNum(); j++) {
            Row row = sheets.getRow(j);
            if (row == null || row.getFirstCellNum() == j || row.getCell(1) == null) {
                continue;
            }
            InnovativeBusiness innovativeBusiness = new InnovativeBusiness();
            for (int y = row.getFirstCellNum(); y < row.getLastCellNum(); y++) {
                cell = row.getCell(y);
                if(cell==null || cell.toString().equals("")){
                    continue;
                }
                switch (y+1){
                    case 2:innovativeBusiness.setTrellisCode(ExcelImport.getCellValue(cell)); break;
                    case 3:innovativeBusiness.setTrellisName(ExcelImport.getCellValue(cell)); break;
                    case 4:innovativeBusiness.setYzStaffId(ExcelImport.getCellValue(cell)); break;
                    case 5:innovativeBusiness.setAccountManager(ExcelImport.getCellValue(cell)); break;
                    case 6:innovativeBusiness.setContractNoGlobal(ExcelImport.getCellValue(cell)); break;
                    case 7:innovativeBusiness.setContractName(ExcelImport.getCellValue(cell)); break;
                    case 8:innovativeBusiness.setCompanyName(ExcelImport.getCellValue(cell)); break;
                    case 9:innovativeBusiness.setTotalAmount(ExcelImport.getCellValue(cell)); break;
                    case 10:innovativeBusiness.setContractContent(ExcelImport.getCellValue(cell)); break;
                    case 11:innovativeBusiness.setRepositoryNameVendor(ExcelImport.getCellValue(cell)); break;
                    case 12:innovativeBusiness.setBusinessCodingCode(ExcelImport.getCellValue(cell)); break;
                    case 13:innovativeBusiness.setBusinessCodingName(ExcelImport.getCellValue(cell)); break;
                    case 14:innovativeBusiness.setContractTimelimitName(ExcelImport.getCellValue(cell)); break;
                    case 15:innovativeBusiness.setStartDate(ExcelImport.getCellValue(cell)); break;
                    case 16:innovativeBusiness.setEndDate(ExcelImport.getCellValue(cell)); break;
                    case 17:innovativeBusiness.setCycleId(ExcelImport.getCellValue(cell)); break;
                    case 18:innovativeBusiness.setAmount(ExcelImport.getCellValue(cell)); break;
                }
            }
            list.add(innovativeBusiness);
            int flag =200;
            if(j%flag==0||j == sheets.getLastRowNum()){
                List<InnovativeBusiness> copy = new ArrayList<>(list);
                lists.add(copy);
                list.clear();
            }
        }
        return lists;
    }

    /**
     * 导入第二发展人
     *
     * @param sheets 第二发展人
     * @return
     */
    public List<List<NmMobileService>> listNmMobile(Sheet sheets) throws Exception {
        List<List<NmMobileService>> lists =new ArrayList<>();
        List<NmMobileService> list = new ArrayList<>();
        Cell cell = null;
        for (int j = sheets.getFirstRowNum() + 1; j <= sheets.getLastRowNum(); j++) {
            Row row = sheets.getRow(j);
            int flag =200;
            if(list.size() !=0 && list.size()%flag ==0 || j == sheets.getLastRowNum()){
                List<NmMobileService> copy = new ArrayList<>(list);
                lists.add(copy);
                list.clear();
            }
            if (row == null || row.getFirstCellNum() == j || row.getCell(1) == null) {
                continue;
            }else if (ExcelImport.isAllRowEmpty(row,row)){
                continue;
            }
            NmMobileService mobileService = new NmMobileService();
            for (int y = row.getFirstCellNum(); y < row.getLastCellNum(); y++) {
                cell = row.getCell(y);
                if(cell==null || cell.toString().equals("")){
                    continue;
                }
                switch (y+1){
                    case 2:mobileService.setTrellisCode(ExcelImport.getCellValue(cell)); break;
                    case 3:mobileService.setTrellisName(ExcelImport.getCellValue(cell)); break;
                    case 4:mobileService.setYzStaffId(ExcelImport.getCellValue(cell)); break;
                    case 5:mobileService.setAccountManager(ExcelImport.getCellValue(cell)); break;
                    case 6:mobileService.setContractNoGlobal(ExcelImport.getCellValue(cell)); break;
                    case 7:mobileService.setContractName(ExcelImport.getCellValue(cell)); break;
                    case 8:mobileService.setRepositoryNameVendor(ExcelImport.getCellValue(cell)); break;
                    case 9:mobileService.setSerialNumber(ExcelImport.getCellValue(cell)); break;
                    case 10:mobileService.setCycleId(ExcelImport.getCellValue(cell)); break;
                    case 11:mobileService.setFee(ExcelImport.getCellValue(cell)); break;
                }
            }
            list.add(mobileService);
        }
        return lists;
    }

    /**
     * 导入物联网业务
     *
     * @param sheets 导入物联网业务
     * @return
     */
    public List<List<NmInternetOfThings>> listNmInternetOfThings(Sheet sheets) throws Exception {
        List<List<NmInternetOfThings>> lists =new ArrayList<>();
        List<NmInternetOfThings> list = new ArrayList<>();
        Cell cell = null;
        for (int j = sheets.getFirstRowNum() + 1; j <= sheets.getLastRowNum(); j++) {
            Row row = sheets.getRow(j);
            int flag =200;
            if(list.size() !=0 && list.size()%flag ==0 ||j == sheets.getLastRowNum()){
                List<NmInternetOfThings> copy = new ArrayList<>(list);
                lists.add(copy);
                list.clear();
            }
            if (row == null || row.getFirstCellNum() == j || row.getCell(1) == null) {
                continue;
            }else if (ExcelImport.isAllRowEmpty(row,row)){
                continue;
            }
            NmInternetOfThings internetOfThings = new NmInternetOfThings();
            for (int y = row.getFirstCellNum(); y < row.getLastCellNum(); y++) {
                cell = row.getCell(y);
                if(cell==null || cell.toString().equals("")){
                    continue;
                }
                switch (y+1){
                    case 2:internetOfThings.setTrellisCode(ExcelImport.getCellValue(cell)); break;
                    case 3:internetOfThings.setTrellisName(ExcelImport.getCellValue(cell)); break;
                    case 4:internetOfThings.setYzStaffId(ExcelImport.getCellValue(cell)); break;
                    case 5:internetOfThings.setAccountManager(ExcelImport.getCellValue(cell)); break;
                    case 6:internetOfThings.setContractNoGlobal(ExcelImport.getCellValue(cell)); break;
                    case 7:internetOfThings.setContractName(ExcelImport.getCellValue(cell)); break;
                    case 8:internetOfThings.setRepositoryNameVendor(ExcelImport.getCellValue(cell)); break;
                    case 9:internetOfThings.setSerialNumber(ExcelImport.getCellValue(cell)); break;
                    case 10:internetOfThings.setCycleId(ExcelImport.getCellValue(cell)); break;
                    case 11:internetOfThings.setFee(ExcelImport.getCellValue(cell)); break;
                }
            }
            list.add(internetOfThings);

        }
        return lists;
    }


    /**
     * 判断文件格式
     *
     * @param inStr
     * @param fileName
     * @return
     * @throws Exception
     */
    public static Workbook getWorkbook(InputStream inStr, String fileName) throws Exception {
        Workbook workbook = null;
        String fileType = fileName.substring(fileName.lastIndexOf("."));
        if (".xls".equals(fileType)) {
            workbook = new HSSFWorkbook(inStr);
        } else if (".xlsx".equals(fileType)) {
            workbook = new XSSFWorkbook(inStr);
        } else {
            throw new Exception("请上传excel文件！");
        }
        inStr.close();
        return workbook;
    }




}
